<?php
/**
 * Created by PhpStorm.
 * User: 许文能
 * Date: 2016/8/25 0025
 * Time: 下午 3:13
 */
namespace Company\Controller;

use Think\Controller;

class AdSenseController extends Controller
{

    public function getAdSense()
    {
        //  获取数据库广告信息
        $adSense=D("adSense");
        $add=$adSense->select();
        $this->assign("add",$add);
        $this->display();
    }

    public function addAdSense(){
        //添加广告位
        $title=$_POST["position"];
        $d=D("adSense");
        $data["position"]=$title;
        $data["sid"]=1;
        $re=$d->add($data);
        if(!empty($re)){
            $this->success('添加成功','/Ad/getAd');
        }
        else{
            $this->error('添加失败','/Ad/getAd');
        }

    }

    public function upAdSense(){
        //根据id获取表单数据库信息
        $id=$_GET["id"];
        $d=D("adSense");
        $add=$d->where("id='$id'")->select();
        $this->assign("add",$add);
        $this->display();

    }
    public function upDateAdSense(){
        //  显示添加页面

        $this->display();
    }
    public function  edAdSense(){
        //  跟新广告数据库操作
        $id=$_POST["id"];
        $add=$_POST["position"];
        $dd=D("adSense");
        $data["position"]=$add;
        $data["sid"]=1;
        $re=$dd->where("id='$id'")->save($data);
        if(!empty($re)){
            $this->success('更改成功','getAdSense');
        }
        else{
            $this->error('更改失败','getAdSense');
        }
    }

    public function delete(){
        //  删除广告类操作
        $id=$_GET["id"];
        $ad=D("adSense");
        $de = $ad->delete($id);
        if(!empty($de)){
            $this->success('删除成功','/AdSense/getAdSense');
        }
        else{
            $this->error('删除失败','/AdSense/getAdSense');
        }

    }

}